package com.imti.controller;

import com.imti.model.Quest;
import com.imti.service.QuestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@Slf4j
@RequestMapping("/questController")
public class QuestController {
    @Resource
    QuestService questService;


    @GetMapping("/{rid}")
    public String findAllQuest(@PathVariable("rid" ) Integer rid, HttpServletRequest req){
        List<Quest> quests = questService.findAllQuest(rid);
        req.getSession().setAttribute("Quests", quests);
        return "quest/question-list";

    }
    @GetMapping
    public String findAllQuest(Quest quest, HttpServletRequest req){
        List<Quest> quests = questService.findByQuest(quest);
        req.getSession().setAttribute("Quests", quests);
        return "quest/question-list";
    }
    @GetMapping("/toAddQuest/{rid}")
    public String toAddQuest(@PathVariable("rid")int id){
        return "quest/add-question";
    }
    /**
     * 跳转添加题目页面
     * @return
     */
    @RequestMapping("/saveQuest")
    public String saveQuest(Quest quest){
        boolean b = questService.saveQuestionAnswer(quest);
        return "redirect:/questController/"+ quest.getRid();
    }

    @GetMapping("/updateQuest/{rid}")
    public String updateQuest(@PathVariable("rid")int id){
        return "quest/update-question";
    }



}
